package com.keepers.repair.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;

import com.keepers.repair.R;
import com.keepers.repair.helper.ConsValue;
import com.keepers.repair.net.LogUtil;
import com.keepers.repair.utils.AlertToast;
import com.keepers.repair.utils.DialogUtil;
import com.keepers.repair.view.IntercomButton;
import com.keepers.repair.view.OnIntercomListener;
import com.keepers.repair.view.TitleBar;

import java.io.File;

/**
 * auth aboom
 * date 2018/11/26
 */
public class RecordingActivity extends BaseActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recording);
        TitleBar titleBar = f(R.id.title_bar);
        titleBar.initializeHeader("录音");
        IntercomButton intercomButton = f(R.id.intercom);
        intercomButton.setOnIntercomListener(new OnIntercomListener() {
            @Override
            public void onStartRecord() {

            }

            @Override
            public void onFinishedRecord(String audioPath, long millis) {
                LogUtil.e(" audioPath = " + audioPath);
                DialogUtil.showCommonDialog(RecordingActivity.this, "提示", "确定上传吗？", (dialog, which) -> {
                    Intent intent = new Intent();
                    intent.putExtra(ConsValue.INTENT_KEY, audioPath);
                    setResult(Activity.RESULT_OK, intent);
                    finish();
                }, (dialog, which) -> {
                    File file = new File(audioPath);
                    if (file.exists()) {
                        file.delete();
                    }
                });
            }

            @Override
            public void onTimeShort() {
                AlertToast.show("录制时间过短...");
            }
        });
    }
}
